// pages/phone/phone.js
const httpRequest = require('../../utils/http_utils.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: '', //提示信息
    val: '', //输入框值
    RowGuid: '',
    success: '', //成功提示信息
    error: '', //失败提示信息
  },

  withdraw: function() { //返回上一页
    wx.redirectTo({
      url: '../index/index?currentTab=2'
    })
  },

  inputBox: function(e) {
    this.setData({
      val: e.detail.value
    })
  },

  phoModify: function() {
    var that = this
    let mobilePattern = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
    if (this.data.val.length == 0) {
      that.setData({
        info: '请填写手机号'
      })
    } else if (!mobilePattern.test(this.data.val)) {
      that.setData({
        info: '请填写正确的手机号'
      })
    } else {
      let params = {
        RowGuid: this.data.RowGuid,
        Mobile: this.data.val
      }
      httpRequest.PostValidateRequest(httpRequest.apiInfo.UpdataFrameProjectUserMobileApi, {
          "formdatas": params
        },
        function(data) {
          console.log(data);
          if (data == '-2') {
            that.setData({
              info: '当前手机号重复，请重新填写！'
            })
          } else if (data == 'true') {
            that.setData({
              success: '手机号修改成功！'
            })
            wx.redirectTo({
              url: '../index/index?currentTab=2'
            })
            app.globalData.globalphone = that.data.val
          } else {
            that.setData({
              error: '手机号修改失败！'
            })
          }
        },
        function(err) {})
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.data.RowGuid = wx.getStorageSync("UserInfo").AppLogin.RowGuid
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})